package cn.dankal.flyaudio.adapter;

import android.content.Intent;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import cn.dankal.basiclib.base.recyclerview.BaseRecyclerViewAdapter;
import cn.dankal.basiclib.base.recyclerview.BaseRecyclerViewHolder;
import cn.dankal.basiclib.base.recyclerview.OnRvItemClickListener;
import cn.dankal.basiclib.pojo.CreateOrderPreviewEntity;
import cn.dankal.basiclib.pojo.ProductDetailItemEntity;
import cn.dankal.basiclib.util.ActivityUtils;
import cn.dankal.flyaudio.R;
import cn.dankal.flyaudio.personal.MyOrderActivity;
import cn.dankal.flyaudio.store.RefundDetailActivity;

public class OrderRefundAdapter extends BaseRecyclerViewAdapter<CreateOrderPreviewEntity> {
    @Override
    protected int getLayoutResId(int viewType) {
        return R.layout.item_refund;
    }

    @Override
    protected BaseRecyclerViewHolder getViewHolder(ViewGroup parent, View rootView, int viewType) {
        return new ViewHolder(rootView);
    }

    static class ViewHolder extends BaseRecyclerViewHolder<CreateOrderPreviewEntity> {

        public ViewHolder(View itemView) {
            super(itemView);
        }

        @Override
        public void onBindData(CreateOrderPreviewEntity data, int position) {
            if(data.getAfterSaleApply() == null)return;
            RecyclerView list = itemView.findViewById(R.id.rv_products);
            list.setLayoutManager(new LinearLayoutManager(getContext()));
            ProductsAdapter adapter = new ProductsAdapter();
            list.setAdapter(adapter);

            String state = data.getAfterSaleApply().getState();
            String type = "";
            if ("RETURN_MONEY_ONLY".equals(data.getAfterSaleApply().getType())) {
                type = "仅退款";
            } else {
                type = "退货退款";
            }
            if (TextUtils.equals(state, MyOrderActivity.WAITING_SHIP)) {
                setText(R.id.tv_refund_desc, type + " 待买家发货");
            } else if (TextUtils.equals(state, MyOrderActivity.WAITING)) {
                setText(R.id.tv_refund_desc, type + " 退款待处理");
            }else if( TextUtils.equals(state, MyOrderActivity.SHIPPING)){
                setText(R.id.tv_refund_desc, type + " 等待商家收货");
            } else if (TextUtils.equals(state, MyOrderActivity.WAITING_REFUND)) {
                setText(R.id.tv_refund_desc, type + " 商家已收货, 退款中");
            } else if (TextUtils.equals(state, MyOrderActivity.REJECTED)) {
                setText(R.id.tv_refund_desc, type + " 退款关闭");
            } else if (TextUtils.equals(state, MyOrderActivity.REFUND_SUCCESS)) {
                setText(R.id.tv_refund_desc, type + " 退款成功");
            }
            adapter.setOnRvItemClickListener(new OnRvItemClickListener<ProductDetailItemEntity>() {
                @Override
                public void onItemClick(View v, int position, ProductDetailItemEntity data1) {

//                    Intent intent = new Intent(ActivityUtils.getTopActivity(), MyOrderDetailActivity.class);
//                    intent.putExtra("orderUuid", data.getUuid());
//                    ActivityUtils.getTopActivity().startActivity(intent);
                    Intent intent = new Intent(ActivityUtils.getTopActivity(), RefundDetailActivity.class);
                    intent.putExtra("orderUuid", data.getUuid());
                    ActivityUtils.getTopActivity().startActivity(intent);
                }
            });
            adapter.addDatas(data.getOrderItemList(), true);
//            adapter.addDatas(datas,true);
        }
    }
}
